package 尊享面试.数组_字符串;

public class a1427字符串的左右移 {
    static class Solution {
        public String stringShift(String s, int[][] shift) {
            int left = 0;
            int right = 0;
            for (int i = 0; i < shift.length; i++) {
                int dir = shift[i][0];
                int amount = shift[i][1];
                if (dir == 0) {
                    left += amount;
                } else {
                    right += amount;
                }
            }
            String ans;
            int last = left - right;
            last %= s.length();
            if (last > 0) { // 左移
                ans = s.substring(last) + s.substring(0, last);
            } else { // 右移
                last = -last;
                ans = s.substring(s.length() - last) + s.substring(0, s.length() - last);
            }
            return ans;
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        String s = "yisxjwry";
        int[][] shift = {{1, 8}, {1, 4}, {1, 3}, {1, 6}, {0, 6}, {1, 4}, {0, 2}, {0, 1}};
        System.out.println(solution.stringShift(s, shift));
    }
}
